<?php
class Model_Common
{
    public static function MD5Hash($data)
    {
        $str = "PMG" . $data . "PMG";
        return md5($str);
    }
    
    public static function getNowTime()
    {
        return time();
    }
    
    public static function getFomrtTimeHMSByHour($hour, $min = 0)
    {
        $date = Model_Common::getFormatTimeYMD();
        $time = $date . " {$hour}:{$min}:00";
        return date('H:i', Model_Common::getStampTime($time));
    }
    
    public static function getMonthDays($format = "")
    {
        if($format == ""){
            return date("t");
        }else{
            return date("t", self::getStampTime($format));
        }
    }
    
    public static function getFormatTime($timeStamp = -1)
    {
        if($timeStamp == -1){
            $timeStamp = self::getNowTime();
        }else{
            $timeStamp = intval($timeStamp);
        }
        return date('Y-m-d H:i:s', $timeStamp);
    }
   
    public static function getFormatTimeYMD($timeStamp = -1)
    {
        if($timeStamp == -1){
            $timeStamp = self::getNowTime();
        }else{
            $timeStamp = intval($timeStamp);
        }
        return date('Y-m-d', $timeStamp);
    }
    
    public static function getFormatTimeYM($timeStamp = -1)
    {
        if($timeStamp == -1){
            $timeStamp = self::getNowTime();
        }else{
            $timeStamp = intval($timeStamp);
        }
        return date('Y-m', $timeStamp);
    }
    
    public static function getFormatTimeY($timeStamp = -1)
    {
        if($timeStamp == -1){
            $timeStamp = self::getNowTime();
        }else{
            $timeStamp = intval($timeStamp);
        }
        return date('Y', $timeStamp);
    }
    
    public static function getFormatTimeM($timeStamp = -1)
    {
        if($timeStamp == -1){
            $timeStamp = self::getNowTime();
        }else{
            $timeStamp = intval($timeStamp);
        }
        return date('m', $timeStamp);
    }
    
    public static function getFormatTimeD($timeStamp = -1)
    {
        if($timeStamp == -1){
            $timeStamp = self::getNowTime();
        }else{
            $timeStamp = intval($timeStamp);
        }
        return date('d', $timeStamp);
    }
    
    public static function getStampTime($timeFormat)
    {
        $timeFormat = trim($timeFormat);
        return strtotime($timeFormat);
    }
    
    public static function getUploadFileName($fileName)
    {
        $time = explode (" ", microtime());  
        $time = $time[1] . ($time[0]*1000);  
        $time = explode( ".", $time );  
        $name = explode('.', $fileName);
        $ra = rand(0,20);
        return $time[0] . $ra . '.' . end($name);
    }
    
    public static function filterText($input)
    {
        $input = trim($input, "\r\n\t ");
        $input = Eren_Filter::htmlspecialchars($input);
        $input = Eren_Filter::addslashes($input);
        
        return $input;
    }
    
    public static function addBr($str)
    {
        $str = str_replace("\r\n", "<br>", $str);
        $str = str_replace("\n", "<br>", $str);
        return $str;
    }
    
    public static function getWorkTypeName($id)
    {
        $worktypes = Config_Default::getWorkType();
        if(isset($worktypes[$id])){
            return $worktypes[$id];
        }
        
        return $worktypes[8];
    }
    
    public static function getRef()
    {
    	return Eren_Request_URL::getRef();
    }
    
    public static function chs2eng($str)
    {
    	$arr = Config_Default::chs2eng();
    	if(isset($arr[$str])){
    		return $arr[$str];
    	}
    	
    	return 'other';
    }
}

